/**
 * 游戏目录
 *
 * @author li.youxi
 * @date 2017/05/31
 */

require('./index.scss');
var tpl = require('./index.html'),
	doc = document;

var catalogObj = {
	list: [{
		name: '红包雨',
		type: 'rain'
	}, {
		name: '音乐方块',
		type: 'music'
	}],
	init: function(){
		doc.querySelector('#game_catalog').innerHTML = tmpl(tpl, {
			list: this.list
		});

		this.bindEvent();
	},

	setPage: function(type){
		globalMessage.fire('init.'+type);
		gameObj.setStatus('loading', function(){
			globalMessage.fire('init.loading');
		});
	},

	bindEvent: function(){
		var listEl = doc.querySelector('#logList'),
			_this = this;

		listEl.addEventListener('click', function(e){
			var className = e.target.className,type;
			
			if(className.indexOf('catalog-item')!=-1) {
				type = e.target.getAttribute('data-type');	
				_this.setPage(type);			
			}
		}, false);
	}
};

catalogObj.init();